<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/3/11
 * Time: 16:03
 * * @copyright: ©2024 永州微聚商网络科技有限公司
 * @link: https://www.weijuyunke.com
 */


namespace app\admin\controller;

use app\admin\service\AdminUserService;
use app\admin\validate\AdminUserValidate  ;
use app\Request;
use app\services\jwt\JwtService;
use think\Exception;
use think\exception\ValidateException;

class  AdminUser
{
    public function login(Request $request)
    {
        $param = $request->param();
        try {
            validate(AdminUserValidate::class)->check($param);
        } catch (ValidateException $e) {
            return error($e->getError());
        }
        try {
            //查询用户信息
            $AdminUserService = new AdminUserService();
            $result  = $AdminUserService->login($param);
            if ($result['code'] == 0){
                return error($result['msg']);
            }
            // 生成token
            $jwtService =  new JwtService();
            $jwtResult  = $jwtService->getMerchantToken($result['data']['id']);
            return success('成功', $jwtResult['data']);
        }catch (Exception $e) {
            return error($e->getMessage());
        }

    }



}

